package org.lib.rabbitmqhello.try3;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 试验3的配置：TopicExchange
 * @author ben
 * @date 2021-08-27 21:39:53 CST
 */
@Configuration
public class RabbitConfig3 {
	
	public final static String QUEUE_31 = "queue31";
	public final static String QUEUE_32 = "queue32";
	public final static String TOPIC_EXCHANGE_3 = "topic3";
	
	@Bean
	public Queue queue31() {
		return new Queue(QUEUE_31);
	}
	
	@Bean
	public Queue queue32() {
		return new Queue(QUEUE_32);
	}
	
	@Bean
	public TopicExchange topicExchange() {
		// 最简单的构造函数
		return new TopicExchange(TOPIC_EXCHANGE_3);
	}
	
	@Bean
	public Binding binding31(Queue queue31, TopicExchange topicExchange) {
		return BindingBuilder
				.bind(queue31)
				.to(topicExchange)
				// routingKey 为 QUEUE_31——队列名
				.with(QUEUE_31);
	}
	
	@Bean
	public Binding binding32(Queue queue32, TopicExchange topicExchange) {
		return BindingBuilder
				.bind(queue32)
				.to(topicExchange)
				// routingKey 为 *，通配符，所有消息
				.with("*");
	}
	
}
